package com.arvinclub.model.entity;

import com.arvinclub.model.util.ToolsUtil;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.Objects;

/**
 * 用户实体类
 */
public class User {

    /**
     * 用于数据库映射
     */
    private int id;
    private int status;//状态 1正常，0停用:无法登录
    private int admin;//权限
    private int muted;//1禁言，0正常
    private Date muteDeadline;//禁言截止时间 muted为1时才有效

    /**
     * 用于前端显示
     */
    private String muteDeadTime;//muteDeadline 面向前端

    /**
     * 其他
     */
    private int fansCount;
    private int idolCount;

    public int getFansCount() {
        return fansCount;
    }

    public void setFansCount(int fansCount) {
        this.fansCount = fansCount;
    }

    public int getIdolCount() {
        return idolCount;
    }

    public void setIdolCount(int idolCount) {
        this.idolCount = idolCount;
    }

    public String getMuteDeadTime() {
        if (muteDeadTime == null && muteDeadline != null)
            muteDeadTime = ToolsUtil.SIMPLE_DATE_FORMAT.format(muteDeadline);
        return muteDeadTime;
    }

    public void setMuteDeadTime(String muteDeadTime) {
        this.muteDeadTime = muteDeadTime;
    }

    public Date getMuteDeadline() {
        return muteDeadline;
    }

    public void setMuteDeadline(Date muteDeadline) {
        this.muteDeadline = muteDeadline;
    }

    public int getMuted() {
        return muted;
    }

    public void setMuted(int muted) {
        this.muted = muted;
    }

    @NotNull
    @Size(min = 1)
    @Pattern(regexp = "[\\S]+")
    private String name;//用户名

    @NotNull
    @Size(min = 1)
    @Pattern(regexp = "[\\S]+")
    private String password;//密码

    public User() { }

    public User(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getAdmin() {
        return admin;
    }

    public void setAdmin(int admin) {
        this.admin = admin;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "{" + id + ":" + name + "}";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (!(o instanceof User))
            return false;
        User user = (User) o;
        return id == user.getId() || Objects.equals(name, user.getName());
    }

}
